import sys
from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton,QHBoxLayout,QWidget
from PyQt5.QtGui import QIcon

class WinForm(QMainWindow):
    def __init__(self,parnet=None):
        super(WinForm,self).__init__(parnet)
        self.setWindowTitle("关闭窗口案例")
        self.button1=QPushButton('关闭窗口')
        self.button1.clicked.connect(self.onButtonClick)
        layout=QHBoxLayout()
        layout.addWidget(self.button1)
        main_frame=QWidget()
        main_frame.setLayout(layout)
        self.setCentralWidget(main_frame)
    def  onButtonClick(self):
        sender=self.sender()
        print(sender.text()+"发送了")
        qapp=QApplication.instance()
        qapp.quit()
if __name__ == '__main__':
    app=QApplication(sys.argv)
    form=WinForm()
    form.show()
    sys.exit(app.exec_())